package cn.edu.scau.cmi.tangqingning.abstractFactoryMethod;

import cn.edu.scau.cmi.tangqingning.abstractFactoryMethod.insuranceAbstract.Insurance;
import cn.edu.scau.cmi.tangqingning.abstractFactoryMethod.insuranceFactory.AbstractFactory;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;

public class AbstractFactoryController {

    @FXML
    private TextArea textId;

    @FXML
    private ComboBox<String> comboBox;

    @FXML
    private ComboBox<String> factoryComboBox;

	public void Init() {
		ObservableList<String> options = FXCollections.observableArrayList("中国人寿保险公司","平安保险公司");
		ObservableList<String> options1 = FXCollections.observableArrayList("身体受伤","汽车损坏","人员伤亡", "多种事故");
		System.out.println(options);
		this.factoryComboBox.setItems(options);
		this.factoryComboBox.getSelectionModel().select(0);

		this.comboBox.setItems(options1);
		this.comboBox.getSelectionModel().select(0);
	}

	@FXML
    void onShowDataClick(ActionEvent event) {
		Insurance in = null;
		AbstractFactory af = AbstractFactory.getFactory(this.factoryComboBox.getValue());

		switch(this.comboBox.getValue()) {
	        case "身体受伤": in = af.CreateBruise();break;
	        case "汽车损坏": in = af.CreateCarDamaged();break;
	        case "人员伤亡": in = af.CreateCasualty();break;
	        case "多种事故": in = af.CreateAccidents();break;
	        default : break;
	    }
		if(in != null) {
			this.textId.setText(in.getData());
		} else {
			this.textId.setText("创建保险错误");
		}
    }

}

